package com.mall.group_booking.controller;

import com.github.pagehelper.PageInfo;
import com.mall.common.response.CommonResponse;
import com.mall.group_booking.entity.GbRecordVo;
import com.mall.entity.groupbooking.GbRoot;
import com.mall.group_booking.service.BookingRootService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author White
 * @version 1.0
 * @email 616769721@qq.com
 * @date 2021/7/29 20:24
 */
@RestController
@RequestMapping("/bookingRoot")
@CrossOrigin
public class BookingRootController {


    @Autowired
    private BookingRootService bookingRootService;

    /**
     * 查询拼团列表
     * @param root
     * @param pageNum
     * @param pageSize
     * @return
     */
    @PostMapping("/findPage")
    public PageInfo<GbRoot> findPage(
            @RequestBody GbRoot root,
            @RequestParam(value = "page",defaultValue = "1") int pageNum,
            @RequestParam(value = "size",defaultValue = "5") int pageSize
    ) {
        return bookingRootService.findPage(pageNum, pageSize, root);
    }

    /**
     * 查询正在进行的拼团活动
     * @param uid
     * @return
     */
    @GetMapping("/findBookingRoot/{uid}")
    public List<GbRoot> findBookingRoot(@PathVariable Long uid){
        return bookingRootService.findBookingRoot(uid);
    }

    @GetMapping("/updateStatusById")
    public void updateStatusById(
            @RequestParam("id")Integer id,
            @RequestParam("status")String status){
        bookingRootService.updateStatusById(id,status);
    }
}
